@extends('admin.layouts.baseTable')
@section('extends')
    <div class="border clearfix" style="margin: 5px 0 0 15px;">
       <span class="l_f">
        <a title="编辑" onclick="xadmin.open('生成优惠券','{{ route('coupon.create') }}',800,400)"
           href="javascript:;" class="btn btn-xs btn-info"><i
                class="fa fa-edit bigger-120"></i>添加优惠券</a>
       </span>
    </div>
@stop
@section('my-js')
    <script>
        function sign(obj,url,route,model,sign){
            layer.confirm('是否标记为已发放？',function(index){
                $.ajaxSetup({
                    headers: { 'X-CSRF-TOKEN' : '{{ csrf_token() }}' }
                });
                $.ajax({
                    type : 'post',
                    url : url,
                    datatype : 'json',
                    data: {is_sign: sign},
                    beforeSend : function () {
                        index = layer.load(1, {shade: [0.6, '#393D49']});
                    },
                    success: function(response, status, xhr) {
                        switch (response.status) {
                            case 200 :
                                layer.msg(response.msg, {
                                    icon: 1,
                                    time: 1000 //2秒关闭（如果不配置，默认是3秒）
                                }, function(){
                                    var index = parent.layer.getFrameIndex(window.name);
                                    if(model == 'parent') {
                                        parent.layer.close(index);
                                        parent.location.href = route;
                                    } else if (model == 'self'){
                                        layer.close(index);
                                        location.href = route;
                                    }
                                });
                                break;
                            case '422' :
                                if (model == 'parent') {
                                    parent.layer.close(index);
                                    layer.msg(response.msg, {icon: 5,shade: [0.6, '#393D49'],time:2000});
                                } else if (model == 'self') {
                                    layer.close(index);
                                    layer.msg(response.msg, {icon: 5,shade: [0.6, '#393D49'],time:2000});
                                }
                                break;
                        }
                    }
                });

            });
        }
    </script>
@stop
